package com.ericpol.pageobject.copy;

import static org.testng.Assert.assertEquals;
import static org.testng.AssertJUnit.assertTrue;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;

public class Page {

	protected WebDriver driver;

	public Page(WebDriver driver) {
		this.driver = driver;
	}

	protected void assertText(String text) {
		assertEquals(text, driver.findElement(By.linkText(text)).getText());
	}

	protected boolean isTextOnPage(String expected) {

		boolean result = driver.getPageSource().contains(expected);
		return result;
	}

	protected void assertTextPresent(String expected) {
		boolean result = driver.getPageSource().contains(expected);
		assertTrue(result);
	}

	protected void click(By by) {
		driver.findElement(by).click();
	}

	protected void open(String urladdress) {
		driver.get(urladdress);
	}

	protected void insertText(By by, String text) {
		WebElement element = driver.findElement(by);
		element.clear();
		element.sendKeys(text);
	}
}